package com.magina.calendario;

import android.content.Context;
import android.database.Cursor;
import android.view.View;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

import java.util.Calendar;

/**
 * Created by IntelliJ IDEA.
 * User: marcioat
 * Date: 29/05/11
 * Time: 18:05
 * To change this template use File | Settings | File Templates.
 */
public class myCursorAdapter extends SimpleCursorAdapter
{
    private Cursor localCursor;
    private Context localContext;

    public myCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
        super(context, layout, c, from, to);
        this.localCursor = c;
        this.localContext = context;

    }

    @Override
    public void bindView(View view, Context context, Cursor cursor)
    {
        super.bindView(view, context, cursor);
        //if(view.toString() == "DateComent")
        if(cursor.getColumnIndex("Dat_Evento")>-1)
        {
            long timestamp = cursor.getLong(cursor.getColumnIndex("Dat_Evento"));
            Calendar cal = Calendar.getInstance();
            cal.setTimeInMillis(timestamp);

            String strMes = "0" + String.valueOf(cal.get(Calendar.MONTH) +1);
            strMes = strMes.substring(strMes.length()-2);

            String strDia = "0" + String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
            strDia = strDia.substring(strDia.length()-2);

            String strData;
            strData = strDia + "/" + strMes + "/" + String.valueOf(cal.get(Calendar.YEAR));

            TextView text;
            text = (TextView) view.findViewById(R.id.DateComent);
            text.setText(strData);
        }
    }


}
